using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Tracking;
using AppToolkit.WF.Utils;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.Contracts;

namespace AppToolkit.WF.Services
{
    /// <summary>
    /// Tracked state of the workflow instance.
    /// </summary>
    public sealed class WorkflowState : INotifyPropertyChanged
    {
        private readonly Guid _guid;

        /// <summary>
        /// CTOR
        /// </summary>
        /// <param name="guid"></param>
        public WorkflowState(Guid guid)
        {
            Contract.Requires<ArgumentException>(guid != Guid.Empty, "guid");
            this._guid = guid;
        }

        #region Property State
        private string _state;

        /// <summary>
        /// Stringified state of the workflow.
        /// </summary>
        public string State
        {
            get
            {
                return this._state;
            }
            set
            {
                if (this._state != value)
                {
                    this._state = value;
                    OnPropertyChanged("State");
                }
            }
        }
        #endregion

        #region Property Current
        private int _current;

        /// <summary>
        /// Current progress values.
        /// </summary>
        public int Current
        {
            get
            {
                return this._current;
            }
            set
            {
                if (this._current != value)
                {
                    this._current = value;
                    OnPropertyChanged("Current");
                }
            }
        }
        #endregion

        #region Property Maximum
        private int _maximum;

        /// <summary>
        /// Maximum value that the progress is supposed to reach.
        /// </summary>
        public int Maximum
        {
            get
            {
                return this._maximum;
            }
            set
            {
                if (this._maximum != value)
                {
                    this._maximum = value;
                    OnPropertyChanged("Maximum");
                }
            }
        }
        #endregion

        #region INotifyPropertyChanged Members
        private void OnPropertyChanged(string propertyName)
        {
            if (null != PropertyChanged)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Public event that is raised when a property changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion
    }
}
